/*
               File: CursoConversion
        Description: Conversion for table Curso
             Author: GeneXus C# Generator version 10_1_5-40140
       Generated on: 2/21/2011 15:44:42.57
       Program type: Callable routine
          Main DBMS: sqlserver
*/
using System;
using System.Collections;
using GeneXus.Utils;
using GeneXus.Resources;
using GeneXus.Application;
using GeneXus.Metadata;
using GeneXus.Reorg;
using System.Threading;
using GeneXus.Programs;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using GeneXus.Data;
using com.genexus;
using GeneXus.Data.ADO;
using GeneXus.Data.NTier;
using GeneXus.Data.NTier.ADO;
using System.Runtime.Remoting;
using GeneXus.WebControls;
using GeneXus.Http;
using GeneXus.Procedure;
using GeneXus.XML;
using GeneXus.Search;
using GeneXus.Encryption;
using GeneXus.Http.Client;
using System.Xml.Serialization;
using System.Data.SqlTypes;
namespace GeneXus.Programs {
   public class cursoconversion : GXProcedure
   {
      public cursoconversion( )
      {
         this.DisconnectAtCleanup = true;
         context = new GxContext(  );
         DataStoreUtil.LoadDataStores( context);
         dsDefault = context.GetDataStore("Default") ;
         IsMain = true;
      }

      public cursoconversion( IGxContext context )
      {
         this.DisconnectAtCleanup = true;
         context = context.UtlClone();
         this.context = context;
         IsMain = false;
         dsDefault = context.GetDataStore("Default") ;
      }

      public void release( )
      {
      }

      public void execute( )
      {
         initialize();
         executePrivate();
      }

      public void executeSubmit( )
      {
         cursoconversion objcursoconversion;
         objcursoconversion = new cursoconversion();
         objcursoconversion.initialize();
         ThreadPool.QueueUserWorkItem( new WaitCallback( objcursoconversion.executePrivateCatch ));
      }

      void executePrivateCatch( object stateInfo )
      {
         try
         {
            executePrivate();
         }
         catch ( Exception e )
         {
            GXUtil.SaveToEventLog( "Design", e);
            throw e ;
         }
      }

      void executePrivate( )
      {
         /* GeneXus formulas */
         /* Output device settings */
         cmdBuffer=" SET IDENTITY_INSERT [GXA0006] ON "
         ;
         RGZ = new GxCommand(dsDefault.Db, cmdBuffer, dsDefault,0,true,false,null);
         RGZ.ErrorMask = GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK;
         RGZ.ExecuteStmt() ;
         RGZ.Drop();
         /* Using cursor CURSOCONVE2 */
         pr_default.execute(0);
         while ( (pr_default.getStatus(0) != 101) )
         {
            A29CursoDescripcion = CURSOCONVE2_A29CursoDescripcion[0] ;
            A27CursoNumeroAlumnos = CURSOCONVE2_A27CursoNumeroAlumnos[0] ;
            A25CursoId = CURSOCONVE2_A25CursoId[0] ;
            A28CursoAula = CURSOCONVE2_A28CursoAula[0] ;
            A26CursoNombre = CURSOCONVE2_A26CursoNombre[0] ;
            A40001GXC2 = CURSOCONVE2_A40001GXC2[0] ;
            A40000GXC1 = StringUtil.Substring( A26CursoNombre, 1, 5) ;
            /*
               INSERT RECORD ON TABLE GXA0006

            */
            AV2CursoId = A25CursoId ;
            AV3CursoNombre = A40000GXC1 ;
            AV4CursoNumeroAlumnos = A27CursoNumeroAlumnos ;
            AV5CursoAula = A40001GXC2 ;
            AV6CursoDescripcion = A29CursoDescripcion ;
            /* Using cursor CURSOCONVE3 */
            pr_default.execute(1, new Object[] {AV2CursoId, AV3CursoNombre, AV4CursoNumeroAlumnos, AV5CursoAula, AV6CursoDescripcion});
            pr_default.close(1);
            if ( (pr_default.getStatus(1) == 1) )
            {
               context.Gx_err = 1 ;
               Gx_emsg = (String)(GXResourceManager.GetMessage("GXM_noupdate")) ;
            }
            else
            {
               context.Gx_err = 0 ;
               Gx_emsg = "" ;
            }
            /* End Insert */
            pr_default.readNext(0);
         }
         pr_default.close(0);
         cmdBuffer=" SET IDENTITY_INSERT [GXA0006] OFF "
         ;
         RGZ = new GxCommand(dsDefault.Db, cmdBuffer, dsDefault,0,true,false,null);
         RGZ.ErrorMask = GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK;
         RGZ.ExecuteStmt() ;
         RGZ.Drop();
         this.cleanup();
      }

      protected void cleanup( )
      {
         CloseOpenCursors();
         if ( IsMain )
         {
            context.CloseConnections() ;
         }
         exitApplication();
      }

      protected void CloseOpenCursors( )
      {
      }

      public override void initialize( )
      {
         cmdBuffer = "" ;
         scmdbuf = "" ;
         CURSOCONVE2_A29CursoDescripcion = new String[] {""} ;
         CURSOCONVE2_A27CursoNumeroAlumnos = new short[1] ;
         CURSOCONVE2_A25CursoId = new short[1] ;
         CURSOCONVE2_A28CursoAula = new short[1] ;
         CURSOCONVE2_A26CursoNombre = new String[] {""} ;
         CURSOCONVE2_A40001GXC2 = new String[] {""} ;
         A29CursoDescripcion = "" ;
         A26CursoNombre = "" ;
         A40001GXC2 = "" ;
         A40000GXC1 = "" ;
         AV3CursoNombre = "" ;
         AV5CursoAula = "" ;
         AV6CursoDescripcion = "" ;
         Gx_emsg = "" ;
         pr_default = new DataStoreProvider(context, new GeneXus.Programs.cursoconversion__default(),
            new Object[][] {
                new Object[] {
               CURSOCONVE2_A29CursoDescripcion, CURSOCONVE2_A27CursoNumeroAlumnos, CURSOCONVE2_A25CursoId, CURSOCONVE2_A28CursoAula, CURSOCONVE2_A26CursoNombre, CURSOCONVE2_A40001GXC2
               }
               , new Object[] {
               }
            }
         );
         /* GeneXus formulas. */
         context.Gx_err = 0 ;
      }

      private short A27CursoNumeroAlumnos ;
      private short A25CursoId ;
      private short A28CursoAula ;
      private short AV2CursoId ;
      private short AV4CursoNumeroAlumnos ;
      private int GIGXA0006 ;
      private String cmdBuffer ;
      private String scmdbuf ;
      private String Gx_emsg ;
      private String A29CursoDescripcion ;
      private String A26CursoNombre ;
      private String A40001GXC2 ;
      private String A40000GXC1 ;
      private String AV3CursoNombre ;
      private String AV5CursoAula ;
      private String AV6CursoDescripcion ;
      private IGxDataStore dsDefault ;
      private GxCommand RGZ ;
      private IDataStoreProvider pr_default ;
      private String[] CURSOCONVE2_A29CursoDescripcion ;
      private short[] CURSOCONVE2_A27CursoNumeroAlumnos ;
      private short[] CURSOCONVE2_A25CursoId ;
      private short[] CURSOCONVE2_A28CursoAula ;
      private String[] CURSOCONVE2_A26CursoNombre ;
      private String[] CURSOCONVE2_A40001GXC2 ;
   }

   public class cursoconversion__default : DataStoreHelperBase, IDataStoreHelper
   {
      public ICursor[] getCursors( )
      {
         cursorDefinitions();
         return new Cursor[] {
          new ForEachCursor(def[0])
         ,new UpdateCursor(def[1])
       };
    }

    private static CursorDef[] def;
    private void cursorDefinitions( )
    {
       if ( def == null )
       {
          Object[] prmCURSOCONVE2 ;
          prmCURSOCONVE2 = new Object[] {
          } ;
          Object[] prmCURSOCONVE3 ;
          prmCURSOCONVE3 = new Object[] {
          new Object[] {"@AV2CursoId",SqlDbType.SmallInt,4,0} ,
          new Object[] {"@AV3CursoNombre",SqlDbType.VarChar,5,0} ,
          new Object[] {"@AV4CursoNumeroAlumnos",SqlDbType.SmallInt,4,0} ,
          new Object[] {"@AV5CursoAula",SqlDbType.VarChar,20,0} ,
          new Object[] {"@AV6CursoDescripcion",SqlDbType.VarChar,650,0}
          } ;
          def= new CursorDef[] {
              new CursorDef("CURSOCONVE2", "SELECT [CursoDescripcion], [CursoNumeroAlumnos], [CursoId], [CursoAula], [CursoNombre], CONVERT( char(4), CAST([CursoAula] AS decimal(4,0))) AS GXC2 FROM [Curso] ORDER BY [CursoId] ",false, GxErrorMask.GX_NOMASK | GxErrorMask.GX_MASKLOOPLOCK, false, this,prmCURSOCONVE2,100,0,true,false )
             ,new CursorDef("CURSOCONVE3", "INSERT INTO [GXA0006] ([CursoId], [CursoNombre], [CursoNumeroAlumnos], [CursoAula], [CursoDescripcion]) VALUES (@AV2CursoId, @AV3CursoNombre, @AV4CursoNumeroAlumnos, @AV5CursoAula, @AV6CursoDescripcion)", GxErrorMask.GX_NOMASK,prmCURSOCONVE3)
          };
       }
    }

    public void getResults( int cursor ,
                            IFieldGetter rslt ,
                            Object[] buf )
    {
       switch ( cursor )
       {
             case 0 :
                ((String[]) buf[0])[0] = rslt.getVarchar(1) ;
                ((short[]) buf[1])[0] = rslt.getShort(2) ;
                ((short[]) buf[2])[0] = rslt.getShort(3) ;
                ((short[]) buf[3])[0] = rslt.getShort(4) ;
                ((String[]) buf[4])[0] = rslt.getVarchar(5) ;
                ((String[]) buf[5])[0] = rslt.getVarchar(6) ;
                break;
       }
    }

    public void setParameters( int cursor ,
                               IFieldSetter stmt ,
                               Object[] parms )
    {
       switch ( cursor )
       {
             case 1 :
                stmt.SetParameter(1, (short)parms[0]);
                stmt.SetParameter(2, (String)parms[1]);
                stmt.SetParameter(3, (short)parms[2]);
                stmt.SetParameter(4, (String)parms[3]);
                stmt.SetParameter(5, (String)parms[4]);
                break;
       }
    }

 }

}
